package com.school.controller.role;

import com.school.model.Role;
import com.school.model.User;
import com.school.service.RoleService;
import com.school.service.UserService;
import com.school.service.impl.RoleServiceImpl;
import com.school.service.impl.UserServiceImpl;
import com.school.util.RequestJsonUtil;
import com.school.util.ResponseJsonUtil;
import com.school.vo.R;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/role/inserts")
public class InsertsController extends HttpServlet {
    RoleService service = new RoleServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Role> read = RequestJsonUtil.read(req, Role.class);
        // 调用Service中的方法
        List<Role> res = service.insert(read);
        if (res != null && res.size() != 0) {
            // json格式传递到前端
            ResponseJsonUtil.write(resp, R.ok());
        } else {
            // json格式传递到前端
            ResponseJsonUtil.write(resp, R.err());
        }
    }
}
